<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="_meta :: header">
    <title>编辑</title>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form form form-horizontal" id="form-draft-edit" action="#"
              th:action="@{/admin/draft/pptRelease}" th:object="${draft}" enctype="multipart/form-data">

            <input type="hidden" name="audioId"  id="audioId" th:value="${ppt?.id}"/>
            <input type="hidden" name="id"  th:value="${draft.id}"/>

            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        class="c-red"></span>稿件标题：</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" th:value="${draft.draftTitle}" name="draftTitle"  placeholder="修改稿件标题" id="draftTitle" style="width:400px;"/>

                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文件名：</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input"  th:value="${draft.fileName}" name="fileName"  placeholder="修改文件名" id="fileName" style="width:400px;"/>

                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        class="c-red"></span>稿件内容：</label>
                <div class="layui-input-block">
                    <script id="editor" th:text="${draft.draftText}" name="draftText" autofocus type="text/plain" style="height: 500px">
                    </script>
                    <input id="editorInput" type="hidden" name="" th:value="${draft.draftText}">
                </div>
            </div>

<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label"><span-->
<!--                        class="c-red">*</span>稿件类型：</label>-->
<!--                <div class="layui-input-inline" style="line-height:38px">-->
<!--                    <span th:if="${draft.type eq 3}">音频稿件</span>-->
<!--                    <span th:if="${draft.type eq 4}">ppt稿件</span>-->
<!--                </div>-->
<!--            </div>-->
            <div class="layui-form-item " th:if="${pptdraft eq '1001'}">
                <label class="layui-form-label"><span
                        class="c-red"></span>稿件类型：</label>
                <div class="layui-input-inline" style="line-height:38px">
                    PPT稿件
                </div>
            </div>
            <div class="layui-form-item" th:if="${pptFlag eq '1001'}">
                <label class="layui-form-label" th:if="${pptEditFlag eq '1001'}"><span
                        class="c-red"></span>上传PPT：</label>
                <label class="layui-form-label" th:if="${pptFlag eq '1001' and pptEditFlag ne '1001'}">        </label>
<!--                <label class="layui-form-label" th:if="${pptFlag eq '1001' and pptEditFlag eq '1001' and realseFlag eq '1001'}">        </label>-->
                <div class="layui-input-inline">
                    <div style="display:inline" >
                        <label th:for="${'fileupload'}" title="点击上传" th:if="${pptEditFlag eq '1001'}">
                            <a title="上传"
                               class="layui-btn layui-col-md6">上传PPT</a>
                        </label>

<!--                <label class="layui-form-label" th:if="${ppt?.pptUrl}" style="float: left">下载PPT：</label>   application/vnd.sealed-ppt-->
                        <label >
                            <a th:href="${ppt?.pptUrl}" id="pttId"
                               class="layui-btn">下载PPT</a>
                        </label>
                        <input type="hidden" id="pptUrl" th:value="${ppt?.pptUrl}">
                        <input style="display: none" th:id="${'fileupload'}" class="fileupload" type="file"  name="file"
                               multiple="multiple" accept=".pptx,.ppt"  th:data-url="${'/admin/fileUpload/ppt?id='+draft.id}">
                    </div>
                </div>
            </div>


            <div class="layui-form-item" th:if="${checkFlag eq '1001'}">
                <label class="layui-form-label">驳回理由：</label>
                <div class="layui-input-block">
                    <textarea placeholder="请入驳回理由" th:if="${reasonFlag ne '1001'}" type="text" rows="10"   cols="100"  id="disAllowdReason"  name="disAllowdReason"/></textarea>
                    <textarea placeholder="请入驳回理由" th:if="${reasonFlag eq '1001'}" th:text="${reason}" type="text" rows="10"   cols="100"  id="disAllowdReason"  name="disAllowdReason"/></textarea>
                </div>
            </div>

            <div class="layui-input-block" th:if="${buttonFlag eq '1001'}">
                <button type="submit" th:if="${realseFlag eq '1001'}" id="send" class="layui-btn" >发布</button>
                <a th:if="${agreeFlag eq '1001'}" title="通过" href="javascript:;" th:onclick="'pass(' + ${draft.id} + ')'"
                   class="layui-btn"  style="text-decoration:none">通过</a>
                <a  th:if="${rejectFlag eq '1001'}" class="layui-btn" href="javascript:;" id="reject"  th:onclick="'reject(' + ${draft.id} + ')'">
                    驳回
                </a>
                <a  th:if="${changeFlag eq '1001'}" class="layui-btn" href="javascript:;" id="change"  th:onclick="'change(' + ${draft.id} + ')'">
                    修改
                </a>
                <input type="hidden" name="draftNum"  placeholder="修改稿件字数" id="draftNum"/>
            </div>
        </form>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<div th:replace="_footer :: footerjs"></div>
<div th:replace="_ueditor :: ueditor"></div>
<!--/_footer 作为公共模版分离出去-->
<!--/_footer 作为公共模版分离出去-->
<link rel="stylesheet" type="text/css" th:href="@{/xadmin/lib/formSelect/formSelects-v4.css}"/>
<script type="text/javascript" th:src="@{/xadmin/lib/formselect/formSelects-v4.js}"></script>
<script th:src="@{/xadmin/lib/jQuery-File-Upload/js/vendor/jquery.ui.widget.js}"></script>
<script th:src="@{/xadmin/lib/jQuery-File-Upload/js/jquery.iframe-transport.js}"></script>
<script th:src="@{/xadmin/lib/jQuery-File-Upload/js/jquery.fileupload.js}"></script>
<!--请在下方写此页面业务相关的脚本-->
<script>
    $(function(){
        var pptUrl = $('#pptUrl').val();
        if(pptUrl.trim() == ""){
            $('#pttId').hide();
            $('#send').hide();
        }
    });
    $('.fileupload').fileupload({
        dataType: 'json',
        change: function (e, data) {
            var len = $('.imgcon').children().length;
            if (data.files.length > (1 - parseInt(len))) {
                layer.msg('最多上传1个ppt');
                return false;
            }
        },
        start: function (e) {
            layer_msg = layer.msg('正在上传中…', {time: 100000000});
        },
        progressall: function (e, data) {
            $('.layui-layer-msg .layui-layer-content').html('已上传' + (data.loaded / data.total * 100).toFixed(2) + '%');
        },
        done: function (e, data) {
            $('#pttId').attr("href",data.result.msg);
            $('#pttId').show();
            $('#send').show();
            // window.location.reload();
            layer.close(layer_msg);
        }
    });


    layui.use(['form', 'layer','laydate'],function() {
        $ = layui.jquery;
        var form = layui.form,
            laydate = layui.laydate,
            layer = layui.layer;
        lay('.timeSpace').each(function(){
            laydate.render({
                elem: this
                ,trigger: 'click'
                ,type: 'datetime'
            });
        });
    });
    $(function () {
        $("#form-draft-edit").validate({
            rules: {//自定义规则，key:value 的形式，key 是要验证的元素，value 可以是字符串或对象。
                draftTitle:{
                    required: true,
                },
                draftText:{
                    required: true,
                },
                draftNum:{
                    required: true,
                },
                draftType:{
                    required: true,
                },
            },
            onkeyup:false,//类型 Boolean，默认 true，指定是否在敲击键盘时验证。
            debug : true,//进行调试模式（表单不提交）。
            success : "valid",//要验证的元素通过验证后的动作，如果跟一个字符串，会当作一个 css 类，也可跟一个函数。
            submitHandler : function (form) {//通过验证后运行的函数，里面要加上表单提交的函数($(form).ajaxSubmit();)，否则表单不会提交。
//            var data = UE.getEditor('editor').getContent();
//            $("#editorInput").val(data);
                var draftNum = UE.getEditor('editor').getContentTxt().length;
                $("#draftNum").val(draftNum);
                $.lock()
                $(form).ajaxSubmit({//使用 ajax 方式提交
                    type: 'POST',
                    url: "/admin/draft/pptRelease",
                    success: function (data) {
                        if (data.code == "1") {
                            selfmsg('发布成功!', 1, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            selfmsg('发布失败!');
                            $.unlock()
                        }
                    },
                    error: function () {
                        selfmsg('发布异常!', 5);
                        $.unlock()
                    }
                });
            }
        });
    });

    function showTxt()
    {
        var preHtml = UE.getEditor('editor').getContent(); <!-- execCommand( 'preview' );-->
        layer.open({
            title: '稿件预览',
            content: preHtml,
            btn: ['确定', '取消'],
            yes: function(index, layero){//两个参数:当前层索引,当前层DOM对象
                //按钮【确认】的回调
            },
            btn2: function(index, layero){
                //按钮【取消】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            },
        });
    };
</script>
<!--/请在上方写此页面业务相关的脚本-->

<script>
    // function reject(){
    //     if($('#disAllowdReason').val().trim().length == 0){
    //         selfmsg('请输入驳回理由!');
    //         return;
    //     }
    //
    //     $('#reject').submit();
    // }

    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;
        // 监听全选
        form.on('checkbox(checkall)', function(data){

            if(data.elem.checked){
                $('tbody input').prop('checked',true);
            }else{
                $('tbody input').prop('checked',false);
            }
            form.render('checkbox');
        });
        form.on('select(selectchange)', function(data){
            console.log(data.value); //得到被选中的值
            var pageNo = $('#pageNo');
            var Form = $('form')
            pageNo.val(1);
            Form.submit();
            form.render('select');
        });
        //日期时间范围选择
        laydate.render({

        });
        lay('.timeSpace').each(function(){
            laydate.render({
                elem: this
                ,type: 'datetime'
                ,range: true //或 range: '~' 来自定义分割字符
            });
        });
    });
    // function pass(draftId) {
    //     layer.open({
    //         title: '审核提示',
    //         content: '确认审核通过吗?',
    //         btn: ['确认', '取消'],
    //         yes: function(index, layero){//两个参数:当前层索引,当前层DOM对象
    //             //按钮【确认】的回调
    //             $.ajax({
    //                 type:'post',
    //                 url:"/draft/partner/check",
    //                 cache: false,
    //                 data:{"draftId":draftId},  //重点必须为一个变量如：data
    //                 dataType:'json',
    //                 success:function(data){
    //                     if (data.code == "1") {
    //                         selfmsg('审核通过!', 1, function () {
    //                             window.location.reload();
    //                             var index = parent.layer.getFrameIndex(window.name);
    //                             parent.location.reload();
    //                             parent.layer.close(index);
    //                         });
    //                     }else {
    //                         selfmsg('提交失败!');
    //                     }
    //                 },
    //                 error:function(){
    //                     selfmsg('提交异常!',5);
    //                 }
    //             });
    //         },
    //         btn2: function(index, layero){
    //             //按钮【取消】的回调
    //             //return false 开启该代码可禁止点击该按钮关闭
    //         },
    //     });
    // };

    function disallowUtil(draftId,disAllowdReason) {
        layer.open({
            title: '审核提示',
            content: '确认驳回稿件吗?',
            btn: ['确认', '取消'],
            yes: function(index, layero){//两个参数:当前层索引,当前层DOM对象
                //按钮【确认】的回调
                $.ajax({
                    type:'post',
                    url:"/draft/draftFinal/disallowUtil",
                    cache: false,
                    data:{"draftId":draftId,"disAllowdReason":disAllowdReason},  //重点必须为一个变量如：data
                    dataType:'json',
                    success:function(data){
                        if (data.code == "1") {
                            selfmsg('已驳回!', 1, function () {
                                window.location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        }else {
                            selfmsg('驳回失败!');
                        }
                    },
                    error:function(){
                        selfmsg('提交异常!',5);
                    }
                });
            },
            btn2: function(index, layero){
                //按钮【取消】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            },
        });
    };
    function submitFun(act)
    {
        $('#action').val(act);
    };

    function reject(draftId){
        var disAllowdReason = $('#disAllowdReason').val().trim();
        var draftTitle = $('#draftTitle').val()
        var fileName=$('#fileName').val()
        var draftText = UE.getEditor('editor').getContent()
        var draftNum = UE.getEditor('editor').getContentTxt().length;
        console.log("draftTitle"+draftTitle);
        console.log("draftText"+draftText);
        console.log("draftNum"+draftNum);
        if(disAllowdReason.length == 0){
            selfmsg('请输入驳回理由!');
            return;
        }
        $.lock()
        $.ajax({
            type:'post',
            url:"/admin/ppt/SectionLeaderFailedReason",
            cache: false,
            data:{
                "draftId":draftId,
                "reason":disAllowdReason,
                "audioId":$('#audioId').val(),
                "draftTitle":draftTitle,
                "draftText":draftText,
                "draftNum":draftNum,
                "fileName":fileName,
            },  //重点必须为一个变量如：data
            dataType:'json',
            success:function(data){
                if (data.code == "1") {
                    selfmsg('驳回成功!', 1, function () {
                        window.location.reload();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.location.reload();
                        parent.layer.close(index);
                        $.unlock()
                    });
                }else {
                    selfmsg('提交失败!');
                    $.unlock()
                }
            },
            error:function(){
                selfmsg('提交异常!',5);
                $.unlock()
            }
        });
    }
    function change(draftId){
        var disAllowdReason = $('#disAllowdReason').val().trim();
        var draftTitle = $('#draftTitle').val()
        var fileName=$('#fileName').val()
        var draftText = UE.getEditor('editor').getContent()
        var draftNum = UE.getEditor('editor').getContentTxt().length;
        console.log("draftTitle"+draftTitle);
        console.log("draftText"+draftText);
        console.log("draftNum"+draftNum);
        $.lock()
        $.ajax({
            type:'post',
            url:"/admin/ppt/change",
            cache: false,
            data:{
                "draftId":draftId,
                "audioId":$('#audioId').val(),
                "draftTitle":draftTitle,
                "draftText":draftText,
                "draftNum":draftNum,
                "fileName":fileName,
            },  //重点必须为一个变量如：data
            dataType:'json',
            success:function(data){
                if (data.code == "1") {
                    selfmsg('修改成功!', 1, function () {
                        window.location.reload();
                        // var index = parent.layer.getFrameIndex(window.name);
                        // parent.location.reload();
                        // parent.layer.close(index);
                        $.unlock()
                    });
                }else {
                    selfmsg('修改失败!');
                    $.unlock()
                }
            },
            error:function(){
                selfmsg('修改异常!',5);
                $.unlock()
            }
        });
    }

    function pass(draftId) {
        var draftTitle = $('#draftTitle').val()
        var fileName=$('#fileName').val()
        var draftText = UE.getEditor('editor').getContent()
        var draftNum = UE.getEditor('editor').getContentTxt().length;
        layer.open({
            title: '审核提示',
            content: '确认审核通过吗?',
            btn: ['确认', '取消'],
            yes: function(index, layero){//两个参数:当前层索引,当前层DOM对象
                //按钮【确认】的回调
                $.lock()
                $.ajax({
                    type:'post',
                    url:"/admin/ppt/successById",
                    cache: false,
                    data:{
                        "id":$('#audioId').val(),
                        "draftId":draftId,
                        "draftTitle":draftTitle,
                        "draftText":draftText,
                        "draftNum":draftNum,
                        "fileName":fileName,
                    },  //重点必须为一个变量如：data
                    dataType:'json',
                    success:function(data){
                        if (data.code == "1") {
                            selfmsg('审核通过!', 1, function () {
                                window.location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                                $.unlock()
                            });
                        }else {
                            selfmsg('提交失败!');
                            $.unlock()
                        }
                    },
                    error:function(){
                        selfmsg('提交异常!',5);
                        $.unlock()
                    }
                });
            },
            btn2: function(index, layero){
                //按钮【取消】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            },
        });
    };
</script>
</body>
</html>